<template>
  <el-dialog title="洞幅基础信息录入" :visible.sync="dialogVisible" width="40%" :before-close="handleClose">
    <el-form :model="tunnelWidthInfo" label-width="100px" class="demo-form-inline">
      <el-row>
        <el-col :span="12">
          <el-form-item label="洞幅名称">
            <el-input v-model="tunnelWidthInfo.line"></el-input>
          </el-form-item></el-col>
        <el-col :span="12"> <el-form-item label="里程前缀">
            <el-input v-model="tunnelWidthInfo.code"></el-input>
          </el-form-item></el-col>
      </el-row>
      <el-row>
        <el-col :span="12"> <el-form-item label="起始里程">
            <el-input v-model="tunnelWidthInfo.startMilestr"></el-input>
          </el-form-item></el-col>
        <el-col :span="12">
          <el-form-item label="终止里程">
            <el-input v-model="tunnelWidthInfo.endMilestr"></el-input>
          </el-form-item></el-col>
      </el-row>




    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="create">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import api from '../../../api'
import qs from 'qs'
export default {
  data() {
    return {
      dialogVisible: false,
      ctype: [],
      tunnelWidthInfo: {
        dId: '', //隧道id
        line: '', // 洞幅名称
        code: '', // 里程前缀
        startMilestr: '', // 开始里程
        endMilestr: '' // 结束里程
      }
    }
  },
  mounted() {
    this.$bus.$on('onAddTunnelWidth', (flag) => {
      if (this.tunnelWidthInfo.dId == '') {
        this.$message({
          type: 'fail',
          message: '请选择线路!'
        })
        this.dialogVisible = false
      } else {
        this.dialogVisible = true
      }
    })
    this.$bus.$on('onAddTunnelWidthdId', (flag) => {
      this.tunnelWidthInfo.dId = flag
    })
  },
  methods: {
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then((_) => {
          done()
        })
        .catch((_) => { })
    },
    create() {
      if (this.tunnelWidthInfo.dId == '') {
        this.$message({
          type: 'fail',
          message: '请选择线路!'
        })
        return
      }
      // 查询施工方式
      api
        .tunnelWidthSave(qs.stringify(this.tunnelWidthInfo))
        .then((res) => {
          if (res.data.code == 2001) {
            this.$message({
              type: 'success',
              message: '添加成功!'
            })
            this.dialogVisible = false
            this.$bus.$emit('onRefreshtunnelWidth', this.tunnelWidthInfo.dId)
          }
        })
        .catch((err) => {
          console.log(err)
        })
    }
  }
}
</script>

<style>

</style>